﻿using System;
using System.Collections.Generic;
using System.Text;
using BbzaApi;
using BbzaApi.Core;

namespace TestApplication
{
    /// <summary>
    /// A number of example uses of the .Net API for BroadbandStats.co.za
    /// </summary>
    class Program
    {
        const string USERNAME = "username";
        const string PASSWORD = "password";
        const string API_URL = "http://api.broadbandstats.co.za";
        static void Main(string[] args)
        {
            var service = new BbzaService(USERNAME, PASSWORD, API_URL);
            
            //Example Getting exchange by phone number
            var exchanges = service.GetExchangeByPhone("0117870249");
            foreach (BbzaApi.Core.Exchange exch in exchanges)
            {
                PrettyPrintExchange(exch);
            }
            Console.WriteLine();
            //Example getting exchange by code
            exchanges = service.GetExchangeByCode(new[] { "RKMP", "RRDG" });
            foreach (BbzaApi.Core.Exchange exch in exchanges)
            {
                PrettyPrintExchange(exch);
            }
            Console.WriteLine();
        }

        static void PrettyPrintExchange(Exchange exch_)
        {
            Console.WriteLine(string.Format("{0} ({1})", exch_.Name, exch_.Code));
            Console.WriteLine(string.Format("Query => {0}", exch_.QueryMatch));
            Console.WriteLine(string.Format("Error => {0} ({1})", exch_.GetErrorMessage(), exch_.ErrorCode));
            Console.WriteLine();

            Console.WriteLine("Location:");
            Console.WriteLine(string.Format("  Province => {0}", exch_.Location.Province));
            Console.WriteLine(string.Format("  District => {0}", exch_.Location.District));
            Console.WriteLine(string.Format("  Suburb => {0}", exch_.Location.Suburb));
            Console.WriteLine(string.Format("  Longitude => {0}", exch_.Location.Longitude));
            Console.WriteLine(string.Format("  Latitude => {0}", exch_.Location.Latitude));
            Console.WriteLine();

            foreach (ProviderAvailability provider in exch_.Availability)
            {
                Console.WriteLine("Provider:");
                Console.WriteLine(string.Format("  name => {0}", provider.Name));
                Console.WriteLine(string.Format("  max => {0}", provider.MaxSpeed));
                Console.WriteLine(string.Format("  adsl => {0}", provider.AdslEnablement));
                Console.WriteLine(string.Format("  10mbps => {0}", provider.AdslEnablement10Mbps));
                Console.WriteLine(string.Format("  sio => {0}", provider.SelfInstallOption));
            }
        }
    }
}
